function e(e) {
    if (Array.isArray(e)) {
        for (var t = 0, a = Array(e.length); t < e.length; t++) a[t] = e[t];
        return a;
    }
    return Array.from(e);
}

var t = function(e) {
    return e && e.__esModule ? e : {
        default: e
    };
}(require("../helpers/baseBehavior"));

Component({
    behaviors: [ t.default ],
    externalClasses: [ "wux-class" ],
    properties: {
        max: {
            type: Number,
            value: 5
        },
        star: {
            type: String,
            value: "★"
        },
        value: {
            type: Number,
            value: 0,
            observer: function(e, t) {
                this.data.disabled || (this.updateValue(e), this.triggerEvent("change", {
                    value: e
                }));
            }
        },
        activeColor: {
            type: String,
            value: "#fc6"
        },
        margin: {
            type: Number,
            value: 2
        },
        fontSize: {
            type: Number,
            value: 25
        },
        disabled: {
            type: Boolean,
            value: !1
        }
    },
    methods: {
        updateStars: function() {
            var t = this.data.max, a = [].concat(e(new Array(t))).map(function(e, t) {
                return t;
            });
            this.setData({
                stars: a
            });
        },
        updateValue: function() {
            var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : this.data.value, a = this.data, r = a.max, u = a.activeColor, n = t < 0 ? 0 : t > r ? r : t, i = [].concat(e(new Array(r))).reduce(function(e, a, r) {
                var n = r <= t - 1 ? u : "#ccc";
                return e.push(n), e;
            }, []), s = n.toString().split("."), l = 1 === s.length ? [ s[0], 0 ] : s;
            this.setData({
                colors: i,
                value: n,
                cutIndex: 1 * l[0],
                cutPercent: 10 * l[1]
            });
        },
        handlerClick: function(e) {
            var t = e.currentTarget.dataset.index, a = this.data, r = a.value, u = a.disabled, n = r === t + 1 ? t : t + 1;
            if (u) return !1;
            this.setData({
                value: n
            });
        }
    },
    attached: function() {
        this.updateStars(), this.updateValue();
    }
});